<template>
	<view>
		<view class="gt-form-item">
			<view v-if="label" class="gt-form-label-group">
				<view class="row">
					<view class="gt-form-label-left"></view>
					<view v-if="required" class="gt-form-required">*</view>
					<view class="gt-form-label">{{label}}</view>
					<uni-icons v-if="desc" class="gt-form-desc" type="help" size="20" color="#999999"
						@click="showDesc()"></uni-icons>
				</view>
			</view>
			<view class="gt-form-body">
				<view class="gt-form-content">
					<view class="row mr-15 gt-form-radio-item" v-for="(item,index) in list" :key="index"
						:class="value==item.val ? 'gt-form-radio-item-active' : ''" @click="changeRadio(item.val)">
						<view class="gt-form-radio">
							<uni-icons type="checkmarkempty" class="gt-form-radio-icon" color="#ffffff"
								size="10" style="line-height: 10px;"></uni-icons>
						</view>
						<view class="gt-form-check-text">{{item.label}}</view>
					</view>
					<view v-if="value === true || value === false" class="row mr-15 gt-form-radio-item"
						:class="value === true ? 'gt-form-radio-item-active' : ''" @click="changeRadio()">
						<view class="gt-form-radio">
							<uni-icons type="checkmarkempty" class="gt-form-radio-icon" color="#ffffff"
								size="10" style="line-height: 10px;"></uni-icons>
						</view>
					</view>
				</view>
				<view v-if="error!== false" class="gt-form-error">{{error}}</view>
			</view>

		</view>
	</view>
</template>

<script>
	export default {
		name: "gt-input",
		props: {
			value: {
				type: [Number, String, Boolean],
				default: ''
			},
			label: {
				type: String,
				default: ''
			},
			field: {
				type: String,
				default: ''
			},
			desc: {
				type: String,
				default: ''
			},
			required: {
				type: [String, Boolean],
				default: ''
			},
			error: {
				type: [String, Boolean],
				default: false
			},
			list: {
				type: Array,
				default(){
					return [];
				}
			}
		},
		created() {},
		data() {
			return {}
		},
		computed: {},
		methods: {
			changeRadio(e) {
				// console.log(this.value)
				if(this.value === true){
					this.$emit('input',false)
				}else if(this.value === false){
					this.$emit('input',true)
				}else{
					this.$emit('input', e, this.field)
				}
				
				let _this = this;
				setTimeout(()=>{
					_this.$forceUpdate()
				},1000);
				
				
			},
			showDesc() {
				uni.showModal({
					title: this.label,
					content: this.desc,
					showCancel: false
				})
			}
		}
	}
</script>

<style lang="scss">
	.gt-form-radio-item {
		cursor: pointer;
	}

	.gt-form-radio {
		width: 15px;
		height: 15px;
		border: 1px solid #3EAFFF;
		position: relative;
		border-radius: 7.5px;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
	}

	.gt-form-radio-item-active .gt-form-check-text {
		color:  #3EAFFF;
	}

	.gt-form-radio-item-active .gt-form-radio {
		background-color:  #3EAFFF;
	}

	.gt-form-radio-icon {
		display: none;
	}

	.gt-form-radio-item-active .gt-form-radio-icon {
		text-align: center;
		// position: absolute;
		// top: 0;
		// left: 0;
		display: block;
	}
</style>